package site;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.example.sports_meet.R;

import dateBase.Judge_Site_DBHelper;
import util.ToastUtil;

public class Site_add extends AppCompatActivity implements View.OnClickListener {
    private EditText editSno, editSaddress, editScapacity, editStypes, editSname;
    private Button btnSub;
    private Judge_Site_DBHelper mHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_site_add);
        viewInit();

    }

    public void viewInit() {
        editSno = findViewById(R.id.editSno);
        editSname = findViewById(R.id.editSname);
        editSaddress = findViewById(R.id.editSaddress);
        editScapacity = findViewById(R.id.editScapacity);
        editStypes = findViewById(R.id.editStypes);

        findViewById(R.id.btnsub).setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnsub:
                String sno = editSno.getText().toString();
                String scapacity = editScapacity.getText().toString();
                String saddress = editSaddress.getText().toString();
                String stypes = editStypes.getText().toString();
                String sname = editSname.getText().toString();
                SiteBean site = new SiteBean(sno, sname, saddress, scapacity, stypes);
                long result = mHelper.insert(site);

                if (result > 0) {
                    ToastUtil.show(this, "添加成功");
                } else if (result == -1) {
                    ToastUtil.show(this, "添加失败");
                }

                break;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        mHelper = Judge_Site_DBHelper.getInstance(this);
        //打开读写链接
        mHelper.openReadLink();
        mHelper.openWriteLink();
        //获得帮助器实例
    }

    @Override
    protected void onStop() {
        super.onStop();
        mHelper.closeLink();
    }


}
